#include<stdio.h>
#include<string.h>
#include<conio.h>
int n,answ;
int g[16][16],d[16],cost[16];
long int s,ans,sum;
int main()
{
  freopen("c.in","r",stdin);
  long int i,j,k;
  int a[16];
  int kai1,kai;
  while (scanf("%d",&n)!=EOF)
    {
	  for (i=1;i<=n;i++)
	    {
		  scanf("%d%d",&cost[i],&d[i]);
		  for (j=1;j<=d[i];j++)
		    scanf("%d",&g[i][j]);
		}
	  s=1;
	  for (i=1;i<=n;i++) s=s*2;
	  ans=0;
	  for (i=1;i<s;i++)
	    {
		  j=n;k=i;
		  memset(a,0,sizeof(a));
		  while (k!=0)
		    {
			  a[j]=k%2;
			  k=k/2;
			  --j;
			}
		  kai1=1;
		  sum=0;
		  for (j=1;j<=n;j++)
		    {
			  kai=1;
			  if (a[j]==1)
			    {
				  for (k=1;k<=d[j];k++)
			        if (a[g[j][k]]==0) {kai=0;break;}
				  sum+=cost[j];
				} 
     		  if (kai==0) {kai1=0;break;}
			}
		  if (ans<sum && kai1==1)
		    {
			  ans=sum;
			  answ=i;
			}
		}
	  if (ans==0) 
	    {
		  printf("0\n");
		  printf("0\n");
		}
	  else
	    {
		  printf("%d\n",ans);
		  j=n;k=answ;
		  memset(a,0,sizeof(a));
		  while (k!=0)
		    {
			  a[j]=k%2;
			  k=k/2;
			  --j;
			}
		  j=1;while (a[j]==0) ++j;
		  printf("%d",j);
		  for (k=j+1;k<=n;k++)
		    if (a[k]==1) printf(" %d",k);
		  printf("\n");
		} 
	}
  getch();
  return 0;
}